JSP的传递问题 <form name="classid" action="?action=del" method="post" >

来源:百度知道 编辑:UC知道 时间:2024/04/28 18:04:30
<form name="classid" action="?action=del" method="post" >
请选择要删除的新闻类别
<select size="1" name="s1">
<option value="0">选择你要删除的分类。。。</option>
<%while(rs.next()){%>
<option value=<%=rs.getInt("classid")%>><%=rs.getString("classname")%></option>
<%}%>
</select>

<input name="submit" value="删除" type="submit" onClick="return check()">

</form>
<%
String action=request.getParameter("action");
String s1=request.getParameter("s1");
if (action=="del")
{
String sql1="delete * from nclass where classid= '"+s1+"'";
jdbc_sql.update(sql1);
response.sendRedirect("classmange.jsp");

不是没取到值,而是你在比较时语法错了

java中的字符串比较不能直接用 == 号, == 号是判断是否为同一对象

比较字符串用 action.equals("del")

那是因为你的处理页也在此页,而第一次打开时,也会运行下面的程序,所以你必须判断action是否为空, 为空则代表是第一次打开

if ( action != null && action.equals("del") )

action="?action=del" 你这个后面根本就没有s1 ,

request.getParameter("s1"); 又怎么能够获得到呢

action="?action=del"
用SERVLET做这个写法没用过 你确定正确